<template>
	<view class="item">
		<view class="content">
			<view>
				<image src="https://shoujizulin3.hzrjkf.com/static/wxpng/sfztx.png"></image>
			</view>
			<view class="smrz"> 实名认证 </view>
			<view class="smrz2">
				姓名与支付宝实名认证信息相关联且不可更改 <br />
				提交既同意采集人脸照片用于实名认证
			</view>
		</view>
		<view class="bs_xx">
			<view class="sfxx d-c-c d-c">
				<view class="sfxx3">
					<view class="sfxx4 d-s-s d-c">
						<view style="font-size: 30rpx"> 姓名： </view>
						<u--input placeholder="您的姓名" border="surround" :customStyle="{width: '90%', marginTop: '10rpx'}"
							v-model="value1"></u--input>
					</view>

					<view class="sfxx4 d-s-s d-c">
						<view style="font-size: 30rpx"> 身份证号： </view>
						<u--input placeholder="您的身份证号" border="surround"
							:customStyle="{width: '90%', marginTop: '10rpx'}" v-model="value2"></u--input>
					</view>
				</view>

				<view class="anniu">
					<u-button type="primary" text="确定" @click="queding()" :disabled='isdisabled'></u-button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				value1: "",
				value2: "",
				id: "",
				dataurl: "",
				mobile: "",
				isdisabled: false

			};
		},
		onLoad(e) {
			this.id = e.order_id;
			this.getinfo();
		},
		methods: {
			getinfo() {
				let self = this;
				self._get("user.index/setting", {}, function(res) {
					console.log(res.data.userInfo.username, res.data.userInfo.usernum);
					self.value1 = res.data.userInfo.username;
					self.value2 = res.data.userInfo.usernum;
					self.mobile = res.data.userInfo.mobile
				});
			},
			queding() {
				let self = this;
				console.log(self.value1, self.value2);
				self.isdisabled = true
				if (uni.$u.test.idCard(self.value2) == false) {
					uni.showToast({
						title: "身份证号码有误,请重填！",
						duration: 2000,
						icon: "none",
					});
					self.isdisabled = false
					return;
				}

				if (self.value1 == "") {
					uni.showToast({
						title: "姓名不能为空！",
						duration: 2000,
						icon: "none",
					});
					self.isdisabled = true
					return;
				}
				uni.showLoading({
					title: '加载中',
					mask: true
				});
				self._post(
					"user.user/realNameAuthentication", {
						username: self.value1,
						usernum: self.value2,
						mobile: self.mobile
					},
					function(res) {
						console.log(res, '--------')
						self.isdisabled = true
						uni.hideLoading();
						let huoti = uni.getStorageSync('huoti')
						console.log(huoti)
						let type = uni.getSystemInfoSync()
						if (res.code == 1) {
							// #ifdef MP-WEIXIN
							self._post('esign.eqb/authFace', {
								order_id: self.id,
								h5: 'wx',
								username: self.value1,
								usernum: self.value2
							}, (res) => {
								console.log(res, '获取的数据1')
								uni.setStorageSync('flowId', res.data.flowId);
								wx.navigateToMiniProgram({
									appId: 'wx1cf2708c2de46337', // 公证签小程序APPID
									path: `/pages/face/index?bizToken=${res.data.faceToken}`, // 刷脸页面地址
								})
							})
							//#endif
							// #ifdef H5
							if (huoti == true) {
								self._post('esign.Eqb/authFace', {
									username: self.value1,
									usernum: self.value2,
									order_id: self.id,
									mobile: self.mobile
								}, (res) => {
									if (type.osName == 'ios') {
										window.location.href = res.data.originalUrl;
									} else {
										window.open(res.data.originalUrl, Math.random(100), '_self')
									}
								})
							} else {
								self._post('esign.Eqb/face', {
										username: self.value1,
										usernum: self.value2,
										mobile: self.mobile,
										order_id: self.id
									}, (res) => {
										if (type.osName == 'ios') {
											window.location.href = res.data.data.authUrl;
										} else {
											window.open(res.data.data.authUrl, Math.random(100), '_self')
										}
									},
									function(err) {
										console.log(err)
									})
							}
							//#endif
						}
					}
				);
			},
		},
	};
</script>

<style lang="scss">
	.item {
		height: calc(100vh + 400rpx);
	}

	.content {
		width: 100%;
		height: 400rpx;
		background-color: #53a9f4;
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;

		image {
			width: 150rpx;
			height: 150rpx;
		}

		.smrz {
			color: #ffffff;
			margin-top: 20rpx;
			font-size: 30rpx;
		}

		.smrz2 {
			color: #ffffff;
			margin-top: 20rpx;
			line-height: 34rpx;
		}
	}

	.bs_xx {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		background: #f5f5f5;

		.sfxx {
			width: 100%;
			padding: 0 15rpx 15rpx 15rpx;
			background-color: #ffffff;

			.sfxx2 {
				padding: 20rpx 20rpx;

				view {
					color: #43a3e8;
					margin-top: 10rpx;
				}
			}

			.sfxx3 {
				.sfxx4 {
					display: flex;
					width: 600rpx;
					padding: 0;
					margin-top: 20rpx;
				}
			}
		}

		.anniu {
			margin-top: 20rpx;
			width: 85%;
			border-radius: 50rpx;
		}
	}
</style>